home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Code Resources / CalendarMenu MDEF / cTestMain.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-28  |  2.9 KB  |  168 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * cTest.c
  3.  *
  4.  *    A simple demonstration program to test my Calendar MDEF
  5.      Darin Gurney,  Aug '94    CompuServe 71620,2531
  6.  *
  7.  *
  8.  *****/
  9.  
  10. #include "cTestMenus.h"
  11. #include "cTestWindow.h"
  12. #include "CalendarMenu.h"
  13.  
  14. unsigned long    menuDate = 0xa9ff8000;
  15.  
  16. extern    WindowPtr    cTestWindow;
  17. extern    Rect        dragRect;
  18.  
  19. void InitMacintosh(void);
  20. void HandleMouseDown (EventRecord    *theEvent);
  21. void HandleEvent(void);
  22.  
  23. /****
  24.  * InitMacintosh()
  25.  *
  26.  * Initialize all the managers & memory
  27.  *
  28.  ****/
  29.  
  30. void InitMacintosh(void)
  31.  
  32. {
  33.     MaxApplZone();
  34.     
  35.     InitGraf(&thePort);
  36.     InitFonts();
  37.     FlushEvents(everyEvent, 0);
  38.     InitWindows();
  39.     InitMenus();
  40.     TEInit();
  41.     InitDialogs(0L);
  42.     InitCursor();
  43.  
  44. }
  45. /* end InitMacintosh */
  46.  
  47.  
  48. /****
  49.  * HandleMouseDown (theEvent)
  50.  *
  51.  *    Take care of mouseDown events.
  52.  *
  53.  ****/
  54.  
  55. void HandleMouseDown (EventRecord    *theEvent)
  56.  
  57. {
  58.     WindowPtr    theWindow;
  59.     int            windowCode = FindWindow (theEvent->where, &theWindow);
  60.     
  61.     switch (windowCode)
  62.       {
  63.       case inSysWindow: 
  64.         SystemClick (theEvent, theWindow);
  65.         break;
  66.         
  67.       case inMenuBar:
  68.           AdjustMenus();
  69.         HandleMenu(MenuSelect(theEvent->where));
  70.         break;
  71.         
  72.       case inDrag:
  73.           if (theWindow == cTestWindow)
  74.             DragWindow(cTestWindow, theEvent->where, &dragRect);
  75.             break;
  76.             
  77.       case inContent:
  78.           if (theWindow == cTestWindow)
  79.             {
  80.             if (theWindow != FrontWindow())
  81.               SelectWindow(cTestWindow);
  82.             else
  83.             /* Actually should only respond to click in popup menu area,
  84.                 not entire window. */
  85.             /* Note how popup menu will popup with border area under cursor
  86.                if it can't fit on screen.  prevents accidental changes. */
  87.             PopupCalendarMenu( theEvent->where, &menuDate );
  88.               InvalRect(&cTestWindow->portRect);
  89.             }
  90.           break;
  91.           
  92.       case inGoAway:
  93.           if (theWindow == cTestWindow && 
  94.               TrackGoAway(cTestWindow, theEvent->where))
  95.           HideWindow(cTestWindow);
  96.             break;
  97.       }
  98. }
  99. /* end HandleMouseDown */
  100.  
  101.  
  102. /****
  103.  * HandleEvent()
  104.  *
  105.  *        The main event dispatcher. This routine should be called
  106.  *        repeatedly (it  handles only one event).
  107.  *
  108.  *****/
  109.  
  110. void HandleEvent(void)
  111.  
  112. {
  113.     int            ok;
  114.     EventRecord    theEvent;
  115.  
  116.     HiliteMenu(0);
  117.     SystemTask ();        /* Handle desk accessories */
  118.     
  119.     ok = GetNextEvent (everyEvent, &theEvent);
  120.     if (ok)
  121.       switch (theEvent.what)
  122.         {
  123.         case mouseDown:
  124.             HandleMouseDown(&theEvent);
  125.             break;
  126.             
  127.         case keyDown: 
  128.         case autoKey:
  129.             if ((theEvent.modifiers & cmdKey) != 0)
  130.               {
  131.               AdjustMenus();
  132.               HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
  133.               }
  134.             break;
  135.             
  136.         case updateEvt:
  137.             BeginUpdate(cTestWindow);
  138.             DrawcTest(((WindowPeek) cTestWindow)->hilited);
  139.             EndUpdate(cTestWindow);
  140.             break;
  141.             
  142.         case activateEvt:
  143.             InvalRect(&cTestWindow->portRect);
  144.             break;
  145.         }
  146. }
  147. /* end HandleEvent */
  148.  
  149.  
  150. /*****
  151.  * main()
  152.  *
  153.  *    This is where everything happens
  154.  *
  155.  *****/
  156.  
  157.  
  158. main()
  159.  
  160. {
  161.     InitMacintosh();
  162.     SetUpMenus();
  163.     SetUpWindow();
  164.     
  165.     for (;;)
  166.         HandleEvent();
  167. }
  168. /* end main */